package me.vbdetlevvb.plugins.bananasphere;

import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Logger;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.ChatColor;
// Bukkit Imports
// Bukkit Imports
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;

public class Bananasphere extends JavaPlugin {
    protected static final Logger log = Logger.getLogger("Minecraft");
    PluginManager pm ;
    private final BListener listener = new BListener(this);
    
    public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        log.info( "[" + pdfFile.getName() + " ] version " + pdfFile.getVersion() + " enabled" );
        generateWorld();
        //Disable all Worlds
        //for (World world : this.getServer().getWorlds()) {
		//	this.getServer().unloadWorld(world, true);
		//}
        
        pm = this.getServer().getPluginManager();
        pm.registerEvent(Event.Type.PLAYER_JOIN, listener, Event.Priority.Normal, this);
    }
    

    public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        log.info( "[" + pdfFile.getName() + " ] version " + pdfFile.getVersion() + " disabled" );
    }
	
    void generateWorld(){
    	
    	World.Environment env;
		env = World.Environment.NORMAL;
		this.getServer().createWorld("BananaWorld", env, new BWorldGenerator());
		this.getServer().broadcastMessage("BananaWelten wurden geladen.");
		
    }
    
	@SuppressWarnings("deprecation")
	public boolean onCommand(CommandSender sender, Command command, String label, String args[]) {
		if (args.length == 1 && args[0].equalsIgnoreCase("create")) {
			sender.sendMessage(ChatColor.RED + "Generire Welt");
			
			generateWorld();
			
			sender.sendMessage(ChatColor.GREEN + "Fertig");
			return true;
		}else if (args.length == 1 && args[0].equalsIgnoreCase("houses")) {
			Location location;
			location = this.getServer().getWorld("BananaWorld").getSpawnLocation();
			((Player)sender).teleport(location);
			return true;
		}else{
			return false;
		}
		
	}
    
    @Override
    //public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
	public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
        return new BWorldGenerator();
    }
}